const BASE_URL = 'https://tea.qingnian8.com/api/bizhi/';

/**
 * config 默认没传，就是个空对象
 */
export function request(config = {}) {
	const {
		url,
		methodType = 'GET', // 默认GET,枚举值：GET POST 请求
		header = {},
		data = {},
	} = config;
	//  "access-key": "556688aa"
	header.token = '123';
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + url,
			method: methodType,
			header,
			data,
			success: (res) => {
				if (res.data.errCode === 0) {
					resolve(res.data);
				} else if (res.data.errCode === 400) {
					uni.showModal({
						title: '错误提示',
						icon: 'none',
						duration: 2000,
						content: res.data.errMsg,
						showCancel: false,
					});
				} else {
					uni.showToast({
						title: '网络异常',
						duration: 2000,
						icon: 'none',
					});
					resolve(res.data);
				}
			},
			fail: (err) => {
				reject(err);
			},
		});
	});
}
